<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%> 
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- Meta, title, CSS, favicons, etc. -->
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">

<title>随便打TCS系统</title>

<!-- Bootstrap -->
<link href="<%=basePath%>vendors/bootstrap/dist/css/bootstrap.min.css"
	rel="stylesheet">
<!-- Font Awesome -->
<link
	href="//netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"
	rel="stylesheet">
<!-- NProgress -->
<link href="<%=basePath%>vendors/nprogress/nprogress.css"
	rel="stylesheet">
<!-- iCheck -->
<link href="<%=basePath%>vendors/iCheck/skins/flat/green.css"
	rel="stylesheet">

<!-- bootstrap-progressbar -->
<link
	href="<%=basePath%>vendors/bootstrap-progressbar/css/bootstrap-progressbar-3.3.4.min.css"
	rel="stylesheet">
<!-- JQVMap -->
<link href="<%=basePath%>vendors/jqvmap/dist/jqvmap.min.css"
	rel="stylesheet" />
<!-- bootstrap-daterangepicker -->
<link
	href="<%=basePath%>vendors/bootstrap-daterangepicker/daterangepicker.css"
	rel="stylesheet">

<!-- Custom Theme Style -->
<link href="<%=basePath%>build/css/custom.min.css" rel="stylesheet">

<link href="<%=basePath%>static/css/selfshopcategory.css" rel="stylesheet">
</head>

<body class="nav-md">
	<div class="container body">
		<div class="main_container">
			<div class="col-md-3 left_col">
				<div class="left_col scroll-view">
					<div class="clearfix"></div>
					<br />
				</div>
			</div>



			<!-- page content -->
			<div class="right_col" role="main">
				<div class="">
					<div class="page-title">
						<div class="title_left">
							<h3>自营商城分类</h3>
						</div>

						<div class="title_right">
							
						</div>
					</div>

					<div class="clearfix"></div>

					<div class="row">
						<div class="col-md-12">
							<div class="x_panel">
								<div class="x_title">
									<h2>商城分类</h2>
									<ul class="nav navbar-right panel_toolbox">
										<!--<li><a class="collapse-link"> <i
												class="fa fa-chevron-up"></i>
										</a></li>-->
										<!-- <li class="dropdown"><a href="#" class="dropdown-toggle"
											data-toggle="dropdown" role="button" aria-expanded="false">
												<i class="fa fa-wrench"></i>
										</a>
											 <ul class="dropdown-menu" role="menu">
												<li><a href="#">Settings 1</a></li>
												<li><a href="#">Settings 2</a></li>
											</ul></li>-->
										<!-- <li><a class="close-link"> <i class="fa fa-close"></i> 
										</a></li>-->
									</ul>
									<div class="clearfix"></div>
								</div>
								<div class="x_content">

									<div class="row">

										<c:if test="${adminUsergrade == 1}"><p>
										  <input  type="submit" class="btn btn-success" 
										onclick="add_SelfShopCategory()" value="添加一级分类"/>
										   <!--  <input  type="submit" class="btn btn-success" 
										onclick="add_SecondCategory()" value="添加二级分类"/>--></p></c:if>
										<c:forEach items="${selfShopCategory}" var="s" varStatus="z" >
										<div class="col-md-55">
											<div class="thumbnail" onclick="secondCategory('${s.id}')">
												<div class="image view view-first">
													<img style="width: 100%; display: block;"
														src="${s.pic}" alt="image" />
													<div class="mask">
														<div class="tools tools-bottom">
														    <c:if test="${adminUsergrade == 1}">
														    <!--<a href="#" onclick="qianyi('${s.id}','${s.grade}')"> <i class="fa fa-arrow-left"></i></a>  -->
															<a href="#" onclick="updateUrl()"> <i class="fa fa-link"></i></a> 
															<a href="#" onclick="update_SelfShopCategory('${s.id}')"><i class="fa fa-pencil" ></i></a> 
															<c:if test="${s.id != selfShop.couponcat}">
															<a href="#" onclick="dongjie('${s.id}')"> <i class="fa fa-times"></i></a>
															</c:if></c:if>
															<!--<a href="#" onclick="houyi('${s.id}','${s.grade}')"> <i class="fa fa-arrow-right"></i></a>  -->
														</div>
													</div>
												</div>
												<div class="caption">
													<p>${s.category}</p>
												</div>
											</div>
											
											<div class="ClassifySecond" style="display:none">
											     
											</div>
										</div>
										</c:forEach>
								        </div>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
			<!-- /page content -->
	


	<!-- jQuery -->
	<script src="<%=basePath%>vendors/jquery/dist/jquery.min.js">
		$(".fa fa-pencil").click(function(){
			alert("1");
		});
	</script>
	
	<script>
	$(".thumbnail").on("click",function () {
		/* $(this).siblings('.ClassifySecond').slideDown(300); */
		$(this).parent().siblings(".col-md-55").children('.ClassifySecond').slideUp(0);
		if($(this).siblings('.ClassifySecond').css("display")=="none"){
			$(this).siblings('.ClassifySecond').slideDown(300);
		}else{
			$(this).siblings('.ClassifySecond').slideUp(300);
		}
	});
	$(".ClassifySecond>i").on("click",function(){
		console.log("关闭");
		$(this).parent().slideUp(300)
		/* $(this).parent().attr("style","display:none") */
	})
	</script>
	
	<script type="text/javascript">
	function add_SelfShopCategory() {
		location.href = "add_SelfShopCategory";
	}
	function add_SecondCategory() {
		location.href = "add_SecondCategory";
	}
	function update_SelfShopCategory(id) {
		location.href = "update_SelfShopCategory?id=" + id;
	}
	function update_SecondCategory(id) {
		location.href = "update_SecondCategory?id=" + id;
	}
	</script>
    <script type="text/javascript">
	// ajax 对象
	function ajaxObject() {
		var xmlHttp;
		try {
			// Firefox, Opera 8.0+, Safari
			xmlHttp = new XMLHttpRequest();
		} catch (e) {
			// Internet Explorer
			try {
				xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {
					alert("您的浏览器不支持AJAX！");
					return false;
				}
			}
		}
		return xmlHttp;
	}
	
	function dongjie(id) {
		var ajax = ajaxObject();
		ajax.open("post", "delectSelfShopCategory?id=" + id +
			"&datastatus=" + 0, true);
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.onreadystatechange = function() {
			if (ajax.readyState == 4) {
				if (ajax.status == 200) {
					var result = ajax.responseText;
					if (result == "success") {
						//请求成功
						    alert("分类已删除");
							location.href = "selfShopCategory";
					
					} else {
						//请求成功
						alert(result);
						location.href = "selfShopCategory";
					}
				} else {
					//请求失败
					alert("请求终止，请检查操作或联系客服咨询" + ajax.status);
				}
			} else {
			}
		};
		ajax.send();
	}
	
	function secondCategory(id) {
		$.ajax({
            url : "nextCategory", 
            type : 'POST',
            dataType: 'json',  
            async : false,
            data : {
            	"topid" : id
            },
            success : function(data) { 
            	var str='';
            	console.log(data);
            	str += '<p class="title">二级分类</p>';
                str += '<i class="fa fa-close" id="Classifyclose"></i>';
            	$.each(data, function(i, item) {
                    var category= item.category;
                    var id= "'"+item.id+"'";
                    str += '<div class="ClassifyChild" style="margin-top:0">';
                    str += '<p style="line-height: 39px">'+category	+'</p>';
                    str += '<p>';
                    str += '<c:if test="${adminUsergrade == 1}">';
                    str += '<input type="submit" class="btn btn-success" onclick="update_SecondCategory('+id+')" value="修改" />';
                    str += '<input type="submit" class="btn btn-default	" onclick="dongjie('+id+')" value="删除" /></c:if>';
                    str += '</p>';
                    str += '</div>';
                });
                $(".ClassifySecond").html(str);
            }
        });
	}
	</script>
	<!-- Bootstrap -->
	<script src="<%=basePath%>vendors/bootstrap/dist/js/bootstrap.min.js"></script>
	<!-- FastClick -->
	<script src="<%=basePath%>vendors/fastclick/lib/fastclick.js"></script>
	<!-- NProgress -->
	<script src="<%=basePath%>vendors/nprogress/nprogress.js"></script>
	<!-- bootstrap-daterangepicker -->
	<script src="<%=basePath%>vendors/moment/min/moment.min.js"></script>
	<script
		src="<%=basePath%>vendors/bootstrap-daterangepicker/daterangepicker.js"></script>
	<!-- Chart.js -->
	<script src="<%=basePath%>vendors/Chart.js/dist/Chart.min.js"></script>

	<!-- Custom Theme Scripts -->
	<script src="<%=basePath%>build/js/custom.min.js"></script>
	<!-- layui -->
	<script src="<%=basePath%>vendors/layui/layui.js"></script>

</body>
</html>